#include "resourcemanager.h"

ResourceManager::ResourceManager()
{
}

TriMesh * ResourceManager::Get(const QString &name)
{
    std::map<QString,TriMesh*>::iterator it = resources.find(name);
    if(it != resources.end())
    {
        it->second->numReferences++;
        return it->second;
    }

    TriMesh* newr;
    if(name.endsWith("obj") || name.endsWith("OBJ"))
        newr = TriMesh::ReadFromFile(name.toStdString().c_str(),TriMesh::OBJ);
    else if(name.endsWith("off") || name.endsWith("OFF"))
        newr = TriMesh::ReadFromFile(name.toStdString().c_str(),TriMesh::OFF);
    resources[name] = newr;
    newr->numReferences = 1;
    return newr;
}
